<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>AMBHAS: /home/tomer/svn/ambhas/ambhas/sunlib.py Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">AMBHAS
   
   </div>
   
  </td>
  
  
  
   
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
</td>
   
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('sunlib_8py.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">sunlib.py</div>  </div>
</div><!--header-->
<div class="contents">
<a href="sunlib_8py.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a><a class="code" href="namespaceambhas_1_1sunlib.html">00001</a> <span class="comment">#! /usr/bin/env python</span>
<a name="l00002"></a>00002 <span class="comment"># -*- coding: utf-8 -*-</span>
<a name="l00003"></a>00003 <span class="stringliteral">&quot;&quot;&quot;</span>
<a name="l00004"></a>00004 <span class="stringliteral">Created on Mon Feb  7 11:53:29 2011</span>
<a name="l00005"></a>00005 <span class="stringliteral">@author: sat kumar tomer (http://civil.iisc.ernet.in/~satkumar/)</span>
<a name="l00006"></a>00006 <span class="stringliteral"></span>
<a name="l00007"></a>00007 <span class="stringliteral">&quot;&quot;&quot;</span>
<a name="l00008"></a>00008 <span class="keyword">from</span> __future__ <span class="keyword">import</span> division
<a name="l00009"></a>00009 <span class="keyword">import</span> numpy <span class="keyword">as</span> np
<a name="l00010"></a>00010 <span class="keyword">import</span> datetime <span class="keyword">as</span> dt
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 
<a name="l00013"></a><a class="code" href="classambhas_1_1sunlib_1_1sun.html">00013</a> <span class="keyword">class </span><a class="code" href="classambhas_1_1sunlib_1_1sun.html">sun</a>():
<a name="l00014"></a>00014     <span class="stringliteral">&quot;&quot;&quot;</span>
<a name="l00015"></a>00015 <span class="stringliteral">    This class estimate extral-terrestial solar radiation,</span>
<a name="l00016"></a>00016 <span class="stringliteral">    sunset time, sunrise time, daylight hours</span>
<a name="l00017"></a>00017 <span class="stringliteral">    </span>
<a name="l00018"></a>00018 <span class="stringliteral">    Based on the article:</span>
<a name="l00019"></a>00019 <span class="stringliteral">        Empirical Model for Estimating Global Solar Radiation</span>
<a name="l00020"></a>00020 <span class="stringliteral">        on Horizontal Surfaces for Selected Cities in </span>
<a name="l00021"></a>00021 <span class="stringliteral">        the Six Geopolitical Zones in Nigeria</span>
<a name="l00022"></a>00022 <span class="stringliteral">    By:</span>
<a name="l00023"></a>00023 <span class="stringliteral">        M.S. Okundamiya and A.N. Nzeako</span>
<a name="l00024"></a>00024 <span class="stringliteral"></span>
<a name="l00025"></a>00025 <span class="stringliteral">        </span>
<a name="l00026"></a>00026 <span class="stringliteral">    Example:</span>
<a name="l00027"></a>00027 <span class="stringliteral">        lat_deg = 11</span>
<a name="l00028"></a>00028 <span class="stringliteral">        lon_deg = 76</span>
<a name="l00029"></a>00029 <span class="stringliteral">        doy = 180</span>
<a name="l00030"></a>00030 <span class="stringliteral">        foo = sun(doy, lat_deg, lon_deg)</span>
<a name="l00031"></a>00031 <span class="stringliteral">        hourly_etr = foo.hourly_ETR(11.0)</span>
<a name="l00032"></a>00032 <span class="stringliteral">        daily_etr = foo.daily_ETR()</span>
<a name="l00033"></a>00033 <span class="stringliteral">        risetime, settime = foo.set_rise()</span>
<a name="l00034"></a>00034 <span class="stringliteral">    &quot;&quot;&quot;</span>
<a name="l00035"></a>00035     
<a name="l00036"></a>00036 
<a name="l00037"></a><a class="code" href="classambhas_1_1sunlib_1_1sun.html#a75b1eb14d5e4d9089ff5b11cd63500e4">00037</a>     <span class="keyword">def </span><a class="code" href="classambhas_1_1sunlib_1_1sun.html#a75b1eb14d5e4d9089ff5b11cd63500e4">__init__</a>(self, doy, lat_deg, lon_deg, ze=5.5):
<a name="l00038"></a>00038         <span class="stringliteral">&quot;&quot;&quot; initialise the class</span>
<a name="l00039"></a>00039 <span class="stringliteral">        Input:</span>
<a name="l00040"></a>00040 <span class="stringliteral">            doy:            day of year</span>
<a name="l00041"></a>00041 <span class="stringliteral">            lat_deg:        latitude in degree ( south is negative)</span>
<a name="l00042"></a>00042 <span class="stringliteral">            lon_deg:        longitude in degree (west is negative)</span>
<a name="l00043"></a><a class="code" href="classambhas_1_1sunlib_1_1sun.html#ad323cbbcfd71b3b895a951f3037b54a9">00043</a> <span class="stringliteral">            ze :            time zone in hour</span>
<a name="l00044"></a>00044 <span class="stringliteral">        &quot;&quot;&quot;</span>
<a name="l00045"></a>00045         self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#a51d1a09929fc7cb88ff2ed2b09e93708">doy</a> = doy
<a name="l00046"></a>00046         self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#a0ac3fd98328572dd01505661ed177b17">_lat_rad</a> = lat_deg*np.pi/180
<a name="l00047"></a>00047         
<a name="l00048"></a>00048         self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#a7f1a949d69b309ea54f797fcfcec0734">lon_deg</a> = lon_deg
<a name="l00049"></a>00049         self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#ad323cbbcfd71b3b895a951f3037b54a9">ze</a> = ze
<a name="l00050"></a>00050 
<a name="l00051"></a>00051         
<a name="l00052"></a>00052         
<a name="l00053"></a>00053         self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#a09ef1b70a7deac2a67fce36cc63e7ef5">_Isc</a> = 1367 <span class="comment"># solar constant (W/m^2)</span>
<a name="l00054"></a>00054 
<a name="l00055"></a>00055         B_deg = (doy-1)*360/365
<a name="l00056"></a>00056         B_rad = B_deg*np.pi/180
<a name="l00057"></a>00057         
<a name="l00058"></a>00058         E = 3.82*(0.000075 + 0.001868*np.cos(B_rad) - 0.032077*np.sin(B_rad) \
<a name="l00059"></a>00059                     - 0.0141615*np.cos(2*B_rad) -0.04089*np.sin(2*B_rad) )
<a name="l00060"></a>00060         
<a name="l00061"></a>00061         self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#ac03bdfdba248cd2e1ebdfef661e1c90e">_E</a> = E        
<a name="l00062"></a>00062         
<a name="l00063"></a>00063         <span class="comment"># declination</span>
<a name="l00064"></a>00064         delta = 0.4093*np.sin(2*np.pi*(284+doy)/365)
<a name="l00065"></a>00065         self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#ac8f35b26e5ae5dd23099b10ef9d0811c">_delta</a> = delta
<a name="l00066"></a>00066     
<a name="l00067"></a>00067         <span class="comment"># relative distance of the earth from sun</span>
<a name="l00068"></a>00068         dr = 1 + 0.0033*np.cos(2*np.pi*doy/365)
<a name="l00069"></a>00069         self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#a60e5d58a61ed47ad507123fb014d0161">dr</a> = dr
<a name="l00070"></a>00070         
<a name="l00071"></a><a class="code" href="classambhas_1_1sunlib_1_1sun.html#ac538824283d3a844a6cdf862fed41191">00071</a>     <span class="keyword">def </span><a class="code" href="classambhas_1_1sunlib_1_1sun.html#ac538824283d3a844a6cdf862fed41191">hourly_ETR</a>(self,tc):
<a name="l00072"></a>00072         <span class="stringliteral">&quot;&quot;&quot;</span>
<a name="l00073"></a>00073 <span class="stringliteral">        Input:</span>
<a name="l00074"></a>00074 <span class="stringliteral">            tc:     local time in hours</span>
<a name="l00075"></a>00075 <span class="stringliteral">        &quot;&quot;&quot;</span>
<a name="l00076"></a>00076         ze = self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#ad323cbbcfd71b3b895a951f3037b54a9">ze</a>
<a name="l00077"></a>00077         lat_rad = self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#a0ac3fd98328572dd01505661ed177b17">_lat_rad</a>
<a name="l00078"></a>00078         E = self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#ac03bdfdba248cd2e1ebdfef661e1c90e">_E</a> 
<a name="l00079"></a>00079         delta = self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#ac8f35b26e5ae5dd23099b10ef9d0811c">_delta</a>
<a name="l00080"></a>00080         dr = self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#a60e5d58a61ed47ad507123fb014d0161">dr</a>
<a name="l00081"></a>00081         
<a name="l00082"></a>00082         ts = tc + E + self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#a7f1a949d69b309ea54f797fcfcec0734">lon_deg</a>/15 - ze
<a name="l00083"></a>00083         <span class="comment"># hour angle</span>
<a name="l00084"></a>00084         w = ((ts-12)*15)/180.0*np.pi
<a name="l00085"></a>00085         <span class="comment"># hourly ETR</span>
<a name="l00086"></a>00086         I0 = self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#a09ef1b70a7deac2a67fce36cc63e7ef5">_Isc</a>*dr*(np.sin(lat_rad)*np.sin(delta) + 
<a name="l00087"></a>00087                 np.cos(lat_rad)*np.cos(delta)*np.cos(w))
<a name="l00088"></a>00088         
<a name="l00089"></a>00089         <span class="keywordflow">return</span> I0
<a name="l00090"></a>00090     
<a name="l00091"></a><a class="code" href="classambhas_1_1sunlib_1_1sun.html#a7463e325e5c741f3d43cf6c4435cd126">00091</a>     <span class="keyword">def </span><a class="code" href="classambhas_1_1sunlib_1_1sun.html#a7463e325e5c741f3d43cf6c4435cd126">solar_zenith_angle</a>(self,tc):
<a name="l00092"></a>00092         <span class="stringliteral">&quot;&quot;&quot;</span>
<a name="l00093"></a>00093 <span class="stringliteral">        Input:</span>
<a name="l00094"></a>00094 <span class="stringliteral">            tc:     local time in hours</span>
<a name="l00095"></a>00095 <span class="stringliteral">        Output:</span>
<a name="l00096"></a>00096 <span class="stringliteral">            sza:    solar zenith angle in radian</span>
<a name="l00097"></a>00097 <span class="stringliteral">        &quot;&quot;&quot;</span>
<a name="l00098"></a>00098         ze = self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#ad323cbbcfd71b3b895a951f3037b54a9">ze</a>
<a name="l00099"></a>00099         lat_rad = self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#a0ac3fd98328572dd01505661ed177b17">_lat_rad</a>
<a name="l00100"></a>00100         E = self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#ac03bdfdba248cd2e1ebdfef661e1c90e">_E</a> 
<a name="l00101"></a>00101         delta = self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#ac8f35b26e5ae5dd23099b10ef9d0811c">_delta</a>
<a name="l00102"></a>00102         
<a name="l00103"></a>00103         ts = tc + E + self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#a7f1a949d69b309ea54f797fcfcec0734">lon_deg</a>/15 - ze
<a name="l00104"></a>00104         <span class="comment"># hour angle</span>
<a name="l00105"></a>00105         w = ((ts-12)*15)/180.0*np.pi
<a name="l00106"></a>00106         
<a name="l00107"></a>00107         sza = np.arccos(np.sin(lat_rad)*np.sin(delta) + 
<a name="l00108"></a>00108                 np.cos(lat_rad)*np.cos(delta)*np.cos(w))
<a name="l00109"></a>00109         
<a name="l00110"></a>00110         <span class="keywordflow">return</span> sza
<a name="l00111"></a>00111         
<a name="l00112"></a><a class="code" href="classambhas_1_1sunlib_1_1sun.html#ab44f5c73c93e559e622cdd6f160fd622">00112</a>     <span class="keyword">def </span><a class="code" href="classambhas_1_1sunlib_1_1sun.html#ab44f5c73c93e559e622cdd6f160fd622">daily_ETR</a>(self):
<a name="l00113"></a>00113         <span class="stringliteral">&quot;&quot;&quot; </span>
<a name="l00114"></a>00114 <span class="stringliteral">        Returns the daily Extra Terrestial Radiation (ETR)</span>
<a name="l00115"></a>00115 <span class="stringliteral">        Input:</span>
<a name="l00116"></a>00116 <span class="stringliteral">            </span>
<a name="l00117"></a>00117 <span class="stringliteral">        Output:</span>
<a name="l00118"></a><a class="code" href="classambhas_1_1sunlib_1_1sun.html#ae89daab3f0dfe9b266bf799841d09bf5">00118</a> <span class="stringliteral">            </span>
<a name="l00119"></a>00119 <span class="stringliteral">        &quot;&quot;&quot;</span>
<a name="l00120"></a>00120         lat_rad = self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#a0ac3fd98328572dd01505661ed177b17">_lat_rad</a>
<a name="l00121"></a>00121         delta = self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#ac8f35b26e5ae5dd23099b10ef9d0811c">_delta</a>
<a name="l00122"></a>00122         
<a name="l00123"></a>00123         <span class="comment"># sunset hour angle</span>
<a name="l00124"></a>00124         ws = np.arccos(-np.tan(lat_rad)*np.tan(delta))
<a name="l00125"></a>00125         <span class="comment"># maximum sunshine hour lenght</span>
<a name="l00126"></a>00126         self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#ae89daab3f0dfe9b266bf799841d09bf5">N</a> = ws*24/np.pi
<a name="l00127"></a>00127 
<a name="l00128"></a>00128         H0 = (1/np.pi)*self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#a09ef1b70a7deac2a67fce36cc63e7ef5">_Isc</a>*self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#a60e5d58a61ed47ad507123fb014d0161">dr</a>*(ws*np.sin(delta)*np.sin(lat_rad) +
<a name="l00129"></a>00129                 np.cos(delta)*np.cos(lat_rad))
<a name="l00130"></a>00130                 
<a name="l00131"></a>00131         <span class="keywordflow">return</span> H0
<a name="l00132"></a>00132     
<a name="l00133"></a><a class="code" href="classambhas_1_1sunlib_1_1sun.html#a759c8e36b8787b720063b47e1fec00a0">00133</a>     <span class="keyword">def </span><a class="code" href="classambhas_1_1sunlib_1_1sun.html#a759c8e36b8787b720063b47e1fec00a0">set_rise</a>(self):
<a name="l00134"></a>00134         <span class="stringliteral">&quot;&quot;&quot;</span>
<a name="l00135"></a>00135 <span class="stringliteral">        Returns the sun set and rise time</span>
<a name="l00136"></a>00136 <span class="stringliteral">        &quot;&quot;&quot;</span>
<a name="l00137"></a>00137         lon_deg = self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#a7f1a949d69b309ea54f797fcfcec0734">lon_deg</a>
<a name="l00138"></a>00138         lat_rad = self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#a0ac3fd98328572dd01505661ed177b17">_lat_rad</a>
<a name="l00139"></a>00139         delta = self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#ac8f35b26e5ae5dd23099b10ef9d0811c">_delta</a>
<a name="l00140"></a>00140         E = self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#ac03bdfdba248cd2e1ebdfef661e1c90e">_E</a>
<a name="l00141"></a>00141         ze = self.<a class="code" href="classambhas_1_1sunlib_1_1sun.html#ad323cbbcfd71b3b895a951f3037b54a9">ze</a>
<a name="l00142"></a>00142         
<a name="l00143"></a>00143         w1 = np.arccos(- np.tan(delta)*np.tan(lat_rad))
<a name="l00144"></a>00144         ts1 = 12 - w1*180/np.pi/15 
<a name="l00145"></a>00145         ts2 = 12 + w1*180/np.pi/15 
<a name="l00146"></a>00146         
<a name="l00147"></a>00147         tc1 = ts1 - E - lon_deg/15 + ze
<a name="l00148"></a>00148         tc2 = ts2 - E - lon_deg/15 + ze
<a name="l00149"></a>00149         
<a name="l00150"></a>00150         <span class="keywordflow">return</span> tc1, tc2
<a name="l00151"></a>00151 
<a name="l00152"></a>00152 
<a name="l00153"></a><a class="code" href="namespaceambhas_1_1sunlib.html#a0cfb5626d58aa46823d82b2cc9719fb4">00153</a> <span class="keyword">def </span><a class="code" href="namespaceambhas_1_1sunlib.html#a0cfb5626d58aa46823d82b2cc9719fb4">EarthDistance</a>(dn):
<a name="l00154"></a>00154     <span class="stringliteral">&quot;&quot;&quot;</span>
<a name="l00155"></a>00155 <span class="stringliteral">    module to calculate the earth distance in AU</span>
<a name="l00156"></a>00156 <span class="stringliteral">    </span>
<a name="l00157"></a>00157 <span class="stringliteral">    Input:</span>
<a name="l00158"></a>00158 <span class="stringliteral">        dn:    julian day</span>
<a name="l00159"></a>00159 <span class="stringliteral">    </span>
<a name="l00160"></a>00160 <span class="stringliteral">    Output:</span>
<a name="l00161"></a>00161 <span class="stringliteral">        D:     distance of earth to sun in AU</span>
<a name="l00162"></a>00162 <span class="stringliteral">    &quot;&quot;&quot;</span>
<a name="l00163"></a>00163     thetaD = 2*np.pi*dn/365
<a name="l00164"></a>00164     a0 = 1.000110; a1 = 0.034221; b1 = 0.001280; 
<a name="l00165"></a>00165     a2 = 0.000719; b2 = 0.000077;
<a name="l00166"></a>00166     D = np.sqrt(a0+a1*np.cos(thetaD)+b1*np.cos(thetaD)+a2*np.cos(2*thetaD)+b2*np.cos(2*thetaD));
<a name="l00167"></a>00167     <span class="keywordflow">return</span> D
<a name="l00168"></a>00168 
<a name="l00169"></a><a class="code" href="namespaceambhas_1_1sunlib.html#a04f7e0ec86c48fca6825740f837d43eb">00169</a> <span class="keyword">def </span><a class="code" href="namespaceambhas_1_1sunlib.html#a04f7e0ec86c48fca6825740f837d43eb">sun_rise_set</a>(day,month,year,lw=-76.44,ln=11.95):
<a name="l00170"></a>00170     <span class="stringliteral">&quot;&quot;&quot;</span>
<a name="l00171"></a>00171 <span class="stringliteral">    module to calculate the sunset and sunrise time</span>
<a name="l00172"></a>00172 <span class="stringliteral">    </span>
<a name="l00173"></a>00173 <span class="stringliteral">    Input:</span>
<a name="l00174"></a>00174 <span class="stringliteral">        day:    day of the month (0-31)</span>
<a name="l00175"></a>00175 <span class="stringliteral">        month:  month</span>
<a name="l00176"></a>00176 <span class="stringliteral">        year:   year</span>
<a name="l00177"></a>00177 <span class="stringliteral">        lw:     longitude (west positive)</span>
<a name="l00178"></a>00178 <span class="stringliteral">        ln:     latitude (north positive)</span>
<a name="l00179"></a>00179 <span class="stringliteral">    </span>
<a name="l00180"></a>00180 <span class="stringliteral">    Output:</span>
<a name="l00181"></a>00181 <span class="stringliteral">        Trise:     sunrise time in GMT+5.5</span>
<a name="l00182"></a>00182 <span class="stringliteral">        Tset:      sunset time in GMT+5.5</span>
<a name="l00183"></a>00183 <span class="stringliteral">        </span>
<a name="l00184"></a>00184 <span class="stringliteral">    &quot;&quot;&quot;</span>
<a name="l00185"></a>00185     
<a name="l00186"></a>00186     Jdate = dt.date(year,month,day).toordinal()-dt.date(2000,1,1).toordinal() + 2451545
<a name="l00187"></a>00187     n_star = (Jdate - 2451545 - 0.0009) - (lw/360.0)
<a name="l00188"></a>00188     n = round(n_star)
<a name="l00189"></a>00189     J_star = 2451545 + 0.0009 + (lw/360.0) + n
<a name="l00190"></a>00190     
<a name="l00191"></a>00191     M = np.mod(357.5291 + 0.98560028 * (J_star - 2451545), 360.0)
<a name="l00192"></a>00192     C = (1.9148 * np.sin(M*np.pi/180)) + (0.0200 * np.sin(2 * M*np.pi/180)) + (0.0003 * np.sin(3 * M*np.pi/180))
<a name="l00193"></a>00193     
<a name="l00194"></a>00194     <span class="comment">#Now, using C and M, calculate the ecliptical longitude of the sun.</span>
<a name="l00195"></a>00195     lam = np.mod(M + 102.9372 + C + 180,360)
<a name="l00196"></a>00196     
<a name="l00197"></a>00197     <span class="comment">#Now there is enough data to calculate an accurate Julian date for solar noon.</span>
<a name="l00198"></a>00198     Jtransit = J_star + (0.0053 * np.sin(M*np.pi/180)) - (0.0069 * np.sin(2 * lam*np.pi/180))
<a name="l00199"></a>00199     
<a name="l00200"></a>00200     <span class="comment">#To calculate the hour angle we need to find the declination of the sun</span>
<a name="l00201"></a>00201     delta = np.arcsin( np.sin(lam*np.pi/180) * np.sin(23.45*np.pi/180) )*180/np.pi
<a name="l00202"></a>00202     
<a name="l00203"></a>00203     <span class="comment">#Now, calculate the hour angle, which corresponds to half of the arc length of </span>
<a name="l00204"></a>00204     <span class="comment">#the sun at this latitude at this declination of the sun</span>
<a name="l00205"></a>00205     H = np.arccos((np.sin(-0.83*np.pi/180) - np.sin(ln*np.pi/180) * np.sin(delta*np.pi/180)) / (np.cos(ln*np.pi/180) * np.cos(delta*np.pi/180)))*180/np.pi
<a name="l00206"></a>00206     
<a name="l00207"></a>00207     <span class="comment">#Note: If H is undefined, then there is either no sunrise (in winter) or no sunset (in summer) for the supplied latitude.</span>
<a name="l00208"></a>00208     <span class="comment">#Okay, time to go back through the approximation again, this time we use H in the calculation</span>
<a name="l00209"></a>00209     
<a name="l00210"></a>00210     J_star_star = 2451545 + 0.0009 + ((H + lw)/360) + n
<a name="l00211"></a>00211     <span class="comment">#The values of M and λ from above don&#39;t really change from solar noon to sunset, so there is no need to recalculate them before calculating sunset.</span>
<a name="l00212"></a>00212     Jset = J_star_star + (0.0053 * np.sin(M*np.pi/180)) - (0.0069 * np.sin(2 * lam*np.pi/180))
<a name="l00213"></a>00213     
<a name="l00214"></a>00214     <span class="comment">#Instead of going through that mess again, assume that solar noon is half-way between sunrise and sunset (valid for latitudes &lt; 60) and approximate sunrise.</span>
<a name="l00215"></a>00215     Jrise = Jtransit - (Jset - Jtransit)
<a name="l00216"></a>00216     
<a name="l00217"></a>00217     Trise = np.mod(Jrise,1)*24+5.5-12
<a name="l00218"></a>00218     
<a name="l00219"></a>00219     Tset = np.mod(Jset,1)*24+5.5+12
<a name="l00220"></a>00220     
<a name="l00221"></a>00221     <span class="keywordflow">return</span> Trise, Tset 
</pre></div></div><!-- contents -->
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="sunlib_8py.html">sunlib.py</a>      </li>

    <li class="footer">Generated on Sat Jul 21 2012 12:26:08 for AMBHAS by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.6.1 </li>
   </ul>
 </div>


</body>
</html>
